package com.rzjm.api.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rzjm.api.dao.ShopPostRecordDao;
import com.rzjm.api.entity.*;
import com.rzjm.api.service.ShopPostRecordService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


@Service
public class ShopPostRecordServiceImpl extends BaseServiceImpl<ShopPostRecordDao, ShopPostRecord> implements ShopPostRecordService {

    @Resource
    private ShopPostRecordDao shopPostRecordDao;

    @Value("${web.imgprefix}")
    private String imgprefix;//图片地址

    @Override
    public List<ShopPostRecord> getListBySysUserId(User user, Integer page, Integer pageSize) {
        QueryWrapper<ShopPostRecord> qw = new QueryWrapper<>();
        qw.eq("user_id",user.getId());
        List<ShopPostRecord> list = shopPostRecordDao.getPageEntityList(qw,page,pageSize);
        list.forEach(record -> {
            List<String> imgUrls = new ArrayList<>();
            if(StrUtil.isNotEmpty(record.getImgs())){
                String[] imgs = record.getImgs().split(",");
                if(imgs!=null){
                    for (String img : imgs){
                        imgUrls.add(imgprefix + img);
                    }
                }
                record.setImgUrls(imgUrls);
            }
        });
        return list;
    }
}
